<template>
 <view class="goods-item">
   <!-- 左侧的盒子 -->
   <view class="goods-item-left">
       <radio @click="radioClick" :checked="defaultState" color="#C00000" v-if="showRadio"/>
     <image :src="item.goods_small_logo || defaultImage" class="goods-pic" mode="widthFix"></image>
   </view>
   <!-- 右侧的盒子 -->
   <view class="goods-item-right">
     <!-- 商品的名字 -->
     <view class="goods-name">{{defaultName}}</view>
     <view class="goods-info-box">
       <view class="goods-price">¥{{item.goods_price || defaultPrice}}</view>
      <uni-number-box @click="addCount" :min="1" :value="defaultCount" v-if="showNum"></uni-number-box>
     </view>
   </view>
    </view>
</template>

<script>
  export default {
    name:"my-goods",
    props:{
      item:{
        type:Object,
        default:{}
      },
      showRadio:{
        type:Boolean,
        default:false
      },
      showNum:{
        type:Boolean,
        default:false
      }
    },
    filters:{
     tofixed(num){
       // 将数字转换为带两位小数点的数字
       return Number(num).toFixed(2)
     }
    },
    data() {
      return {
        // 默认的图片
        defaultImage:'https://p1.ssl.qhimgs1.com/sdr/400__/t047ee60bab5a1de3c1.jpg',
        defaultPrice:290,
        defaultId:1,
        defaultName:'如果真相带来痛苦,谎言只会雪上加霜',
        defaultCount:1,
        defaultState:false
      };
    },
    methods:{
      radioClick(){
        this.$emit('radio-change',{
          goods_id:this.defaultId,
          goods_state:!this.defaultState,
        })
      },
      addCount(){
        this.defaultCount+1
      }
    }
  }
</script>

<style lang="scss">
.goods-item{
  display: flex;
  padding: 10px 5px;
  border-bottom: 1px solid red;
  .goods-item-left{
    margin-right: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .goods-pic{
      width: 100px;
      height: 100px;
      display: block;
    }
  }
  .goods-item-right{
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-between;
    .goods-name{
      font-size: 13px
    }
    .goods-info-box{
      display: flex;
      justify-content: space-between;
      align-items: center;
      .goods-price{
        color: #C00000;
        font-size: 16px;
      }
    }
  }
}
</style>